package 
{
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import id.core.TouchSprite;
	/**
	 * ...
	 * @author Aydarka
	 */
	public class Picture extends TouchSprite
	{
		public var url:String;
		public var ind:Number;
public var pic_loader:Loader;
public var pile:TouchSprite;
public var loaderName:String;
		public function Picture(source:String,index:Number):void 
		{
			url = source;
			ind = index;
			this.tabIndex=ind;
		drawLoader();
			
		}
		public function drawLoader():void 
		{
			var pic_request:URLRequest = new URLRequest(url);
			pic_loader = new Loader();
				pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loaded);
				pic_loader.load(pic_request)
		}
		private function on_loaded(e:Event):void
		{
			
			//trace("Загрузка завершена")
			var flashmo_bm:Bitmap = new Bitmap();
			
			pile = new TouchSprite();
			
			flashmo_bm = Bitmap(e.target.content);
			flashmo_bm.x = -flashmo_bm.width * 0.5;
			flashmo_bm.y = -flashmo_bm.height * 0.5;
			flashmo_bm.smoothing = true;
			
			var bg_width = flashmo_bm.width + 10;
			var bg_height = flashmo_bm.height + 10;
			
			
			pile.graphics.beginFill(0x666666);
			pile.graphics.drawRect(-bg_width * 0.51, -bg_height * 0.51, bg_width * 1.02, bg_height * 1.02);
			pile.graphics.beginFill(0xFFFFFF);
			pile.graphics.drawRect(-bg_width * 0.5, -bg_height * 0.5, bg_width, bg_height);
			pile.graphics.endFill();
			var loaderInfo:LoaderInfo = LoaderInfo(e.target.loader.contentLoaderInfo)
			loaderName = loaderInfo.url.substr(16, loaderInfo.url.length);
			pile.scaleX = 0.7;
			pile.scaleY = 0.7;
			
			pile.name = loaderName;
			
			this.addChild(pile)
		pile.addChild(flashmo_bm);
	
			
		
		
		
		}
	}
	
}